package testers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import workables.DatabaseConnector;

/**
 * Servlet implementation class testServleT
 */
public class testServleT extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	DatabaseConnector z;
    public testServleT() {
        super();
        try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out=response.getWriter();
		response.setContentType("text/html");
		
		out.print("apache working on Servlet");
		DatabaseConnector x=new DatabaseConnector();
		out.print("umri");
		System.out.print(x.insertDevice("PosledenOpit", "kubea"));
		x.checkTable();
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out=response.getWriter();
		response.setContentType("text/html");
		if (request.getParameter("pinNumber")!=null)
			{
				out.print("we have a pinPost");
			   try
			    {
				    DatabaseConnector x=new DatabaseConnector();
					x.insertDevice("210000Abeggga", "kubeabearva");
					x.checkTable();
				}
				catch (Exception e)
				{
					System.out.print("exception");
				}
			}
		out.println("apache working on Servlet");
		out.close();
	}

}
